package gazzera.swing.components;

import java.awt.*;

import javax.swing.*;

public class Box extends JPanel
{
	int index;
	boolean vertical;
	
	public Box(boolean vertical)
	{
		super(new GridBagLayout());
		this.vertical = vertical;
	}

	public void add(Component comp, boolean grow)
	{
		GridBagConstraints c = new GridBagConstraints();

		c.gridx = vertical ? 0 : index;
		c.gridy = vertical ? index : 0;
		if(grow)
		{
			c.weightx = 1;
			c.weighty = 1;
			c.fill = GridBagConstraints.BOTH;
		}
		else
		{
			c.weightx = vertical ? 1 : 0;
			c.weighty = vertical ? 0 : 1;
			c.fill = vertical ? GridBagConstraints.HORIZONTAL : GridBagConstraints.VERTICAL;
		}
		add(comp, c);
		
		index++;
	}
}
